<%--
  Created by IntelliJ IDEA.
  User: 17420
  Date: 2021/7/30
  Time: 17:03
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" type="text/css" href="layui/css/layui.css">
    <script src="layui/layui.js"></script>
    <script src="js/jquery.js"></script>
    <title>电影管理</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }

        b {
            font-weight: normal;
        }

        .layui-table,
        .layui-table-view {
            margin: 0px;
        }

        .layui-btn+.layui-btn {
            margin-left: 0px;
        }

        #all_light {
            opacity: 0.8;
            width: 100%;
            height: 2300px;
            background: #000;
            position: absolute;
            top: 0;
            left: 0;
            display: none;
            z-index: 1;
        }

        #contes {
            width: 500px;
            background: #fff;
            display: none;
            z-index: 2;
            position: absolute;
            top: 100px;
            left: 400px;
        }

        #gb {
            float: right;
        }

        .btn {
            margin-top: 10px;
            margin-bottom: 10px;
            margin-left: 20px;
        }

        .pages {
            height: 50px;
            margin-left: 30px;
        }

        .pages b {
            height: 25px;
            width: 25px;
            display: block;
            float: left;
            border-radius: 15px;
            background-color: #fff;
            font-size: 12px;
            text-align: center;
            line-height: 25px;
            margin: 10px 5px;
            background-color: #ccc;
            cursor: pointer;
        }

        .infos li button {
            position: absolute;
            top: 60px;
            left: 630px;
        }

        .txt {
            overflow: hidden;
            white-space: nowrap;
            text-overflow: ellipsis;
            max-width: 100px;
        }

        td {}
    </style>
</head>

<body>
<ul class="layui-nav">
    <li class="layui-nav-item">
        <a href="#">控制台</a>
        <dl class="layui-nav-child">
            <!-- 二级菜单 -->
            <dd><a href="userAdmin.jsp">用户管理</a></dd>
            <dd><a href="filmAdmin.jsp">影片管理</a></dd>
        </dl>
    </li>
    <li class="layui-nav-item">
        <a href=""><img src="img/1.jpg" class="layui-nav-img">我</a>
        <dl class="layui-nav-child">
            <dd><a href="Logout">退出</a></dd>
        </dl>
    </li>

</ul>
<div class="btn">
    <button class="layui-btn layui-btn-radius" onclick="add()">添加</button>
</div>
<table class="layui-table">
    <colgroup>
        <col width="150">
        <col width="200">
        <col>
    </colgroup>
    <thead>
    <tr>
        <th>id</th>
        <th>电影名</th>
        <th>上映时间</th>
        <th>导演</th>
        <th>演员</th>
        <th>片长</th>
        <th>评分</th>
        <th>评分人数</th>
        <th>地区</th>
        <th>语言</th>
        <th>类型</th>
        <th>简介</th>
        <th>操作</th>
    </tr>
    </thead>
    <tbody class="infos">
    <c:forEach items="${movieList}" var="movie">
        <tr>
            <td>${movie.id}</td>
            <td>${movie.name}</td>
            <td>${movie.year}</td>
            <td>${movie.direct}</td>
            <td>${movie.actor}</td>
            <td>${movie.length}</td>
            <td>${movie.grade}</td>
            <td>${movie.number}</td>
            <td>${movie.area}</td>
            <td>${movie.language}</td>
            <td>${movie.type}</td>
            <td class="txt">${movie.content}</td>
            <td>
                <a href="Admin?method=movie&Id=${movie.id}"><button type="button" class="layui-btn layui-btn-primary layui-btn-sm">
                    <i class="layui-icon">&#xe640;</i></button></a>
            </td>
        </tr>
    </c:forEach>
    </tbody>
</table>
<div class="pages"></div>
<!--  弹框的div -->
<div id="contes">

    <form class="layui-form" action="Admin?method=addMovie" method="post">
        <button type="reset" class="layui-btn layui-btn-primary" onclick="off()" id="gb">关闭</button>
        <div class="layui-form-item">
            <label class="layui-form-label">设置电影名:</label>
            <div class="layui-input-block">
                <input type="text" name="name" required lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">设置年代:</label>
            <div class="layui-input-block">
                <input type="text" name="year" required lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">设置导演:</label>
            <div class="layui-input-inline">
                <input type="text" name="direct" required lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">设置主演:</label>
            <div class="layui-input-block">
                <input type="text" name="actor" required lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">设置语言:</label>
            <div class="layui-input-block">
                <input type="text" name="language" required lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">设置地区:</label>
            <div class="layui-input-block">
                <input type="text" name="area" required lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">设置时长:</label>
            <div class="layui-input-block">
                <input type="text" name="length" required lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">设置类型</label>
            <div class="layui-input-block">
                <select name="type" lay-verify="required">
                    <option value="喜剧">喜剧</option>
                    <option value="爱情">爱情</option>
                    <option value="悬疑">悬疑</option>
                    <option value="动作">动作</option>
                    <option value="科幻">科幻</option>
                    <option value="动画">动画</option>
                </select>
            </div>
        </div>
        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label">设置简介</label>
            <div class="layui-input-block">
                <textarea name="content" placeholder="请输入内容" class="layui-textarea"></textarea>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" lay-filter="formDemo" type="submit">立即提交</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>
    </form>

</div>
<div id="all_light">
</div>

<script>
    $(function() {
        var cur = 1; //当前页
        var pagesize = 15; //设置每页尺寸

        var renpage = function() {
            //定义函数，处理分页
            var x = (cur - 1) * pagesize;
            var y = cur * pagesize;
            $('.infos').find('tr').hide().slice(x, y).show()
        }

        //以下代码添加分页
        var n = $('.infos').find('tr').length; //总记录条数
        var pages = Math.ceil(n / pagesize); //计算总页数

        for (let p = 0; p < pages; p++) {
            $("<b>" + (p + 1) + "</b>").appendTo($('.pages')).click(function() {
                cur = p + 1;
                $('body,html').animate({
                        scrollTop: 0
                    },
                    100);
                renpage();
            });
        }

        renpage(); //当页面加载时也要初始化分页

    })
    window.onload = function() {
        //翻页高亮：
        var ele = document.querySelectorAll('.pages b');
        ele[0].style.backgroundColor = "#999"
        for (var i = 0; i < ele.length; i++) {
            ele[i].onclick = function() {
                for (var i = 0; i < ele.length; i++) {
                    ele[i].style.backgroundColor = "";
                }
                this.style.backgroundColor = '#999';
            }
        }
    }
    var o = document.querySelectorAll('.txt');
    for (v of o) {
        txt = v.innerHTML;
        v.setAttribute('title', txt)
    }

    function off() {
        document.getElementById('all_light').style.display = 'none';
        document.getElementById('contes').style.display = 'none';
    }

    function add() {
        document.getElementById('all_light').style.display = 'block';
        document.getElementById('contes').style.display = 'block';
    }
    layui.use('form', function() {
        var form = layui.form;

        //监听提交
        form.on('submit(formDemo)', function(data) {
            layer.msg(JSON.stringify(data.field));
            return false;
        });
    });
    layui.use('element', function() {
        var element = layui.element;
    });
</script>
</body>

</html>